package com.nuanshui.heatedloan.credit.pay.validation;

import com.nuanshui.heatedloan.credit.constant.OrderType;
import com.nuanshui.heatedloan.credit.facade.PayOrderInfoService;
import com.nuanshui.heatedloan.credit.pay.PayRequest;
import com.nuanshui.heatedloan.credit.pay.TransRequestCode;
import com.nuanshui.heatedloan.credit.pay.annotation.ValidationAttribute;
import com.nuanshui.heatedloan.credit.pay.constant.PayBehaviorType;
import com.nuanshui.heatedloan.credit.vo.PayOrderInfoVO;
import org.springframework.beans.factory.annotation.Autowired;

@ValidationAttribute(group = PayBehaviorType.PrepareOrderBehavior,order = 1)
public class OrderValidation extends BaseValidation {

    @Override
    public ValidationResult validate(PayRequest request) {
        ValidationResult validationResult=null;

        PayOrderInfoVO payOrderInfoVO=request.getOrder();
        if(payOrderInfoVO==null){
            validationResult=new ValidationResult(ValidationResultCode.NO_PAY_ORDER);
            return validationResult;
        }
        //给客户打款
        if(TransRequestCode.TRX_CODE_SINGLE_PAY.equals(request.getTransRequestCode())){
             //放款失败或者审核通过
              if(payOrderInfoVO.getOrderStatus()==OrderType.APPROVEDORDER){
                  validationResult=new ValidationResult(ValidationResultCode.VALIDATION_SUCCESS);
              }else{
                  validationResult=new ValidationResult(ValidationResultCode.NO_PAY_STATUS);
              }
        }
        //客户还款
        else if(TransRequestCode.TRX_CODE_REPAY.equals(request.getTransRequestCode())){
            //逾期未还款和未逾期待还款
            if(payOrderInfoVO.getOrderStatus()== OrderType.OVERDUEPAYMENT||
                    payOrderInfoVO.getOrderStatus()==OrderType.NOREIMBURSEMENT){
                validationResult=new ValidationResult(ValidationResultCode.VALIDATION_SUCCESS);
            }else{
                validationResult=new ValidationResult(ValidationResultCode.NO_REPAY_STATUS);
            }
        }
        return validationResult;
    }
}
